﻿using System;
using SharpKit.JavaScript;
using SharpKit.jQuery;
using XWeb.SharpKit.Razor;

namespace Demo1
{
	[JsType(JsMode.Global, OrderInFile = 1000)]
    public class Program: jQueryContext
    {
		static Models.Sample1Model CreateNewModel()
		{
			var model = new Models.Sample1Model { Title = "Title of the model", Items = new JsArray<Models.Sample1Model.Item>(JsMath.round(JsMath.random() * 10) + 5) };
			for (var i = 0; i < model.Items.Length; i++)
				model.Items[i] = new Models.Sample1Model.Item { Name = "Item " + (i + 1), Count = JsMath.round(JsMath.random() * 1000) };
			return model;
		}

		[JsMethod(GlobalCode = true)]
		public static void Main()
		{
			J(() => J("#Generate").click(e => J("#Result").html(Views.Sample1.View.Execute(CreateNewModel()))));
		}
    }
}
